var PublishMember = {
//	account : null,		
	load : function () {
//		var qs =  new QueryString();
//		PublishMember.account = qs.get("customerAccount");
//		if (!PublishMember.account) {
//			PublishMember.account = getUser().Account;
//		}
		 
		Ext.QuickTips.init();
		this.eventRegister();
 
		PublishMember.createGrid(); //建立 Ext table
  
		waitShow();
		Ext.Ajax.request ({
			url : "/ad/sys/com/control/publish/UserService.php?action=queryTargetAccountMember",
			callback : function (op, sc, resp) {
				var obj =  resp.responseText.toJSON();	
//				var notify = new Ext.XTemplate(
//		            '<tpl for=".">',
//		               '<li>{#}.<span class="date">{CreateTime:this.fn}</span><span class="announce">{Content}</span></li>',
//		            '</tpl>',
//		            {
//		            	fn : function (time) {
//		            		return time.toDateString();
//		            	}
//		            }
//		        );
//		    
//		        var pay = new Ext.XTemplate(
//		            '<tpl for=".">',
//		               '<li>{#}.<span class="date">{createtime:this.fn}</span>	<span class="currency">{pay}(元)</span></li>',
//		            '</tpl>',
//		            {
//			            fn : function (time) {
//			            	return time.toDateString("mm月dd日");
//			            }
//		            }
//		        );
//		        notify.overwrite("notify", obj.notify);
//				pay.overwrite("pay", obj.pay);
				
				waitHide();
		       
			}
		});  
		
	},
	 
	eventRegister : function () {
	    Ext.get("btnQuery").on('click',this.query);  //確認,新增使用者	
	    Ext.get("btnAdd").on('click',this.addMember);  //確認,新增使用者	
	}, 
	addMember : function () {
		window.location='/ad/html/publish/publishAccount.php';
		
	},
	
	query : function () {
		var name = Ext.getDom("name").value;
		
		PublishMember.store.reload({
			params:{
				start:0,
				limit:20,
				name : name
			}
		});  
		
	},
	
	createGrid : function () {
	 	 PublishMember.store = new Ext.data.JsonStore ({
	 	 	url:"/ad/sys/com/control/publish/UserService.php?action=queryTargetAccountMember",
			root : "row", 
			remoteSort: false,
			totalProperty: 'count',
			fields : ["account", "name", "settle"]
		});
		
		 
		PublishMember.grid =new Ext.grid.GridPanel({
			renderTo : "grid",
			store :  PublishMember.store,
			height: 450,
		    //autoWidth: true,
			loadMask : true,
			viewConfig : {
				forceFit : true 
			},
			columns : [ 
				new Ext.grid.RowNumberer(),
				{header : "客戶ID" ,dataIndex : "account", width :100,sortable : true 
					,renderer: function (value, p , record) {
						return "<a href='/ad/html/publish/publishAccount.php?editType=1&account="+value+"'>"+value+"</a>";
					} },
				{header : "客戶名稱", dataIndex : "name",width :100, sortable : true 
					/*,renderer: function (value, p , record) {
						switch (value) {
							case "0": return "審理中";
							case "1": return "刊登中";
							case "2": return "已結束";
							case "3": return "暫停";
							case "4": return "刪除";
						}
					} */
				},
				{header : "應用程式", dataIndex : "account",width :40, sortable : false 
					,renderer: function (value, p , record) {
						return "<a href='/ad/html/publish/publishMAppList.php?account="+value+"'>管理</a>";
					} 
				},
				{header : "帳戶餘額", dataIndex : "settle",width :50 , sortable : true},
				{header : "帳務", dataIndex : "account" , width : 40, sortable : false
					,renderer: function (value, p , record) {
						return "<a href='/ad/sys/com/control/publish/UserService.php?action=getUserOverload&managerAccount="+value+"'>管理</a>";
					} 	
				}
			],
			
			bbar : new Ext.PagingToolbar({
				pageSize :20,
				store : PublishMember.store,
				displayInfo : true,
				displayMsg : "顯示第 {0} 筆到 {1} 筆紀錄,共 {2} 筆紀錄",
				emptyMsg : "沒有紀錄" 
			})
		});	
		
		PublishMember.store.load({
			params:{
				start:0,
				limit:20
			}
		});    
	}
	 
};

Ext.onReady(function (){
	PublishMember.load();
});


